<%-- 
    Document   : result.jsp
    Created on : Apr 29, 2008, 5:14:07 AM
    Author     : Administrator
--%>
<%@ page import="java.util.GregorianCalendar" %>
<%@ page import="java.util.*" %>
<%@ page import="Model.Trip" %>
<%@ page import="Model.Model" %>
<%@ page import="AirLine.Flight" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Iterator" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Result</h2>
        <p>
          
        <%--
            List trips = (List) request.getAttribute("trips");
            Iterator it = trips.iterator();
            while(it.hasNext()){
                out.print("<br>trip: " + it.next());
            }
        --%>
        <%
        
       // out.print(((Model)session.getAttribute("model")).getErrorMessage());
            Set trips = (Set) session.getAttribute("trips");
            session.setAttribute("trips", trips);
            Iterator<Trip> it = trips.iterator();
            
            for(int num=0; it.hasNext(); num++ ){
                Trip temp = it.next();
                out.print("<h3>" + temp.getDepartureAirport() + " -->>" 
                            + temp.getDestinationAirport()
                            + " price: " + temp.getPrice() + "<br></h3>");
                List<Flight> flights = temp.getFlights();
                Iterator<Flight> it2 = flights.iterator();
                out.print("detail: ");
        %>
        <a href="<%= request.getContextPath() + "/booktrip.jsp?id=" + num%>">Book This Trip</a>
        <table border="3">
        <thead>
        <tr>
            <th>Airline</th>
            <th>Departure Airport</th>
            <th>Destination Airport</th>
            <th>Departure Time</th>
            <th>Destination Time</th>
            <th>Free Seats</th>
            <th>Price</th>
        </tr>
        </thead>
        <tbody>
        <%
                while( it2.hasNext() ){
                    Flight tempFlight = it2.next();
                    String airline = tempFlight.getAirline().getName();
                    String departureAirport = tempFlight.getDepartureAirport().getAirportName();
                    String arrivalAirport = tempFlight.getDestinationAirport().getAirportName();
                    
                    Date d1 = tempFlight.getDepartureTime();
                    String departureTime = d1.toString();
                    Date d2 = tempFlight.getArrivalTime();
                    String arrivalTime = d2.toString();
                    
                    String freeSeats = "" + tempFlight.getNumberOfFreeSeats();
                    String price = "" + tempFlight.getPrice();
        %>
        <tr>
        <td><%=airline%></td>
        <td><%=departureAirport%></td>
        <td><%=arrivalAirport%></td>
        <td><%=departureTime%></td>
        <td><%=arrivalTime%></td>
        <td><%=freeSeats%></td>
        <td><%=price%></td>
        </tr>
        <%
                }
        %>
        </tbody>
        </table>              
                <%
                
            }
        %>

        
    </body>
</html>
